package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PublicOpinionCase;
import com.ruoyi.system.service.IPublicOpinionCaseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 案例Controller
 * 
 * @author ruoyi
 * @date 2021-09-15
 */
@RestController
@RequestMapping("/system/case")
public class PublicOpinionCaseController extends BaseController
{
    @Autowired
    private IPublicOpinionCaseService publicOpinionCaseService;


    /**
     * 案例分组统计incident_roots_msg
     */
    @GetMapping(value = "/getGroupByIncidentRootsMsg")
    public AjaxResult getGroupByIncidentRootsMsg()
    {
        return AjaxResult.success(publicOpinionCaseService.getGroupByIncidentRootsMsg());
    }

    /**
     * 查询案例列表
     */
    @PreAuthorize("@ss.hasPermi('case:list')")
    @GetMapping("/list")
    public TableDataInfo list(PublicOpinionCase publicOpinionCase)
    {
        startPage();
        List<PublicOpinionCase> list = publicOpinionCaseService.selectPublicOpinionCaseList(publicOpinionCase);
        return getDataTable(list);
    }

    /**
     * 导出案例列表
     */
    @PreAuthorize("@ss.hasPermi('case:export')")
    @Log(title = "案例", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PublicOpinionCase publicOpinionCase)
    {
        List<PublicOpinionCase> list = publicOpinionCaseService.selectPublicOpinionCaseList(publicOpinionCase);
        ExcelUtil<PublicOpinionCase> util = new ExcelUtil<PublicOpinionCase>(PublicOpinionCase.class);
        return util.exportExcel(list, "案例数据");
    }

    /**
     * 获取案例详细信息
     */
    @PreAuthorize("@ss.hasPermi('case:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(publicOpinionCaseService.selectPublicOpinionCaseById(id));
    }

    /**
     * 新增案例
     */
    @PreAuthorize("@ss.hasPermi('case:add')")
    @Log(title = "案例", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PublicOpinionCase publicOpinionCase)
    {
        return toAjax(publicOpinionCaseService.insertPublicOpinionCase(publicOpinionCase));
    }

    /**
     * 修改案例
     */
    @PreAuthorize("@ss.hasPermi('case:edit')")
    @Log(title = "案例", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PublicOpinionCase publicOpinionCase)
    {
        return toAjax(publicOpinionCaseService.updatePublicOpinionCase(publicOpinionCase));
    }

    /**
     * 删除案例
     */
    @PreAuthorize("@ss.hasPermi('case:remove')")
    @Log(title = "案例", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(publicOpinionCaseService.deletePublicOpinionCaseByIds(ids));
    }
}
